package com.example.cpoopc.helloretrofit.bean;

import android.os.Parcel;
import android.os.Parcelable;

import org.json.JSONException;
import org.json.JSONObject;

public class JayInfo implements Parcelable{
        UserInfo jayInfo;// 杰伦信息
        int jayType;// 操作类型(点赞，评论)
        ReplyInfo jayReply;// 评论信息ReplyInfo(仅操作类型为点赞时)
        public JayInfo(UserInfo jayInfo, int jayType, ReplyInfo jayReply) {
            super();
            this.jayInfo = jayInfo;
            this.jayType = jayType;
            this.jayReply = jayReply;
        }
        
        private JayInfo(Parcel source){
            jayInfo = UserInfo.CREATOR.createFromParcel(source);
            jayType = source.readInt();
            jayReply = ReplyInfo.CREATOR.createFromParcel(source);
        }
        
        public static final Creator<JayInfo> CREATOR = new Creator<JayInfo>() {
            
            @Override
            public JayInfo[] newArray(int size) {
                // TODO Auto-generated method stub
                return new JayInfo[size];
            }
            
            @Override
            public JayInfo createFromParcel(Parcel source) {
                // TODO Auto-generated method stub
                return new JayInfo(source);
            }
        };
        
        @Override
        public int describeContents() {
            return 0;
        }
        @Override
        public void writeToParcel(Parcel dest, int flags) {
            jayInfo.writeToParcel(dest, flags);
            dest.writeInt(jayType);
            jayReply.writeToParcel(dest, flags);
        }
        
        public JSONObject toJsonObject() throws JSONException{
            JSONObject jb = new JSONObject();
            if(jayInfo!=null){
                jb.put("jayinfo", jayInfo.toJsonObject());
            }
            jb.put("jayType", jayType);
            return jb;
            
        }
    }